using Yoozoo.Managers;

namespace Gameplay.PVE.TurnBase
{
    public class ControlElement : ElementBase
    {
        private int controlType;
        public override void Parse(TbsSkillElementConfig config)
        {
            base.Parse(config);
            controlType = GetValue("ControlType");
            AddControl();
            if (config.flyText != null)
            {
                //PveFlyTextManager.Instance.ShowFlyText(config.flyText,target.Data.position,1,0.8f,ETextColor.Blue);
            }
        }

        private void AddControl()
        {
            var arg = ClassManager.Get<ControlArg>();
            arg.controlType = controlType;
            target.Data.controlList.Add(controlType);
            target.Data.controlList.Sort();
            target.Transmit(ETransmitType.AddControl,arg);
        }

        private void RemoveControl()
        {
            var arg = ClassManager.Get<ControlArg>();
            arg.controlType = controlType;
            target.Data.controlList.Remove(controlType);
            target.Data.controlList.Sort();
            target.Transmit(ETransmitType.RemoveControl,arg);
        }
        

        public override void Free()
        {
            base.Free();
            RemoveControl();
        }
    }
}